﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RPGX.Data;

namespace RPGX.Server
{
    public static class ServerRepository
    {
        public static void SetStatus(ServerStatus status)
        {
            RPGXAuthenticationEntities context = new RPGXAuthenticationEntities();

            string serverName = Configuration.GetCurrentServerName().ToLower().Trim();

            var server = (from s in context.Servers
                          where s.Name.ToLower().Trim() == serverName
                          select s).FirstOrDefault();

            server.Status = (int)status;

            context.SaveChanges();
        }

        public static ServerStatus GetCurrentServerStatus()
        {
            RPGXAuthenticationEntities context = new RPGXAuthenticationEntities();

            string serverName = Configuration.GetCurrentServerName().ToLower().Trim();

            var status = (from s in context.Servers
                          where s.Name.ToLower().Trim() == serverName
                          select s.Status).FirstOrDefault();

            return (ServerStatus)status;
        }
    }
}
